package com.evan.review.ipc;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

/**
 * AIDL远程计算服务
 * 实现ICalcService.aidl定义的接口，提供跨进程的计算功能
 */
public class CalcService extends Service {
    private static final String TAG = "CalcService";

    // 创建Binder对象，实现AIDL接口
    private final ICalcService.Stub binder = new ICalcService.Stub() {
        @Override
        public int add(int a, int b) throws RemoteException {
            Log.d(TAG, "add: " + a + " + " + b);
            return a + b;
        }

        @Override
        public int subtract(int a, int b) throws RemoteException {
            Log.d(TAG, "subtract: " + a + " - " + b);
            return a - b;
        }
    };

    @Override
    public IBinder onBind(Intent intent) {
        Log.d(TAG, "CalcService onBind");
        return binder;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "CalcService onCreate");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "CalcService onDestroy");
    }
} 